<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script type="text/javascript" src="js/vue.js"></script>
    <script type="text/javascript" src="js/axios.min.js"></script>
    <script type="text/javascript" src="js/qs.min.js"></script>


</head>
<body>
    <form method="post" action="/inner/auth/login">
        <input name="username" :value="username">
        <input name="password" :value="password">
        <input name="targetUrlKey" hidden th:value="${targetUrlKey}">
        <button @click="login">登陆</button>
    </form>
    <script>
        const instance = axios.create({
            baseURL: 'https://gateway.51xuecheng.cn/inner/auth/',
            timeout: 10000,
            headers: {'X-Custom-Header': 'foobar'}
        });

        // 添加请求拦截器
        instance.interceptors.request.use(function (config) {
            // 在发送请求之前做些什么
            return config;
        }, function (error) {
            // 对请求错误做些什么
            return Promise.reject(error);
        });

        // 添加响应拦截器
        instance.interceptors.response.use(function (response) {
            // 2xx 范围内的状态码都会触发该函数。
            // 对响应数据做点什么
            console.log(response)
            if (response.status==302) {
                redirectLocation=response.headers["Location"]

            }
            // return response;
        }, function (error) {
            // 超出 2xx 范围的状态码都会触发该函数。
            // 对响应错误做点什么
            console.log("eror")
            console.log(error)
            return Promise.reject(error);
        });
        new Vue({
            data:{
                username:"",
                password:"",
                targetUrlKey:"",
                params:{},
                authCodeUrl:{}
            },
            methods:{
                login(){
                    this.targetUrlKey=this.params.targetUrlKey
                    instance.post("/inner/auth",qs.stringify({
                        username:this.username,
                        password:this.password,
                        targetUrlKey:this.targetUrlKey
                    }))
                },
                getParams(){
                    let params = {}

                    if (url.indexOf('?') !== -1) {

                        let arr = url.split('?')[1].split('&')

                        arr.forEach((item) => {

                            let val = item.split('=')

                            params[val[0]] = val[1]

                        })

                    }
                    this.params=params
                }
            },
            mounted(){
                this.getParams()
            }
        })
    </script>
</body>
</html>